package com.xuxk.project.oauth.controller.rpc;

import com.github.pagehelper.Page;
import com.xuxk.project.oauth.annotation.OauthLog;
import com.xuxk.project.oauth.bean.XuxkRole;
import com.xuxk.project.oauth.service.XuxkRoleService;
import com.xuxk.project.oauth.util.PageInfoVo;
import com.xuxk.project.oauth.util.PageUtil;
import com.xuxk.project.oauth.util.RequestUtils;
import com.xuxk.project.oauth.util.ResultBodyVo;
import com.xuxk.project.oauth.vo.XuxkRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
 *   @author  橙云科技有限公司
 *  只对内部服务开放，不对第三方开放
 */

@RequestMapping("/rpc/xuxkRole")
@RestController
public class XuxkRoleController  {

    @Autowired
	XuxkRoleService xuxkRoleService;


    /**
    * 分页查询
    * @param pageNum  页码
    * @param pageSize 页行数
    * @param request
    * @return
    */
    @GetMapping(value = "/v1.0/xuxkRoles", produces = MediaType.APPLICATION_JSON_VALUE)
    @OauthLog(eventName = "分页查询角色列表信息")
	public PageInfoVo xuxkRoles(Integer pageNum, Integer pageSize, HttpServletRequest request){

        Map<String,Object> paramMap = RequestUtils.getQueryParams(request);

        Page<XuxkRoleVo> pageResult = xuxkRoleService.listXuxkRoles(paramMap, PageUtil.getPageParam(pageNum,pageSize));

		return  new PageInfoVo(pageResult) ;
	}




    @GetMapping(value="/v1.0/xuxkRoles/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @OauthLog(eventName = "获取角色信息")
    public XuxkRole getXuxkRole(@PathVariable Integer id) {
        XuxkRole xuxkRole = xuxkRoleService.getXuxkRole(id );

        return xuxkRole;
    }

    @PostMapping(value="/v1.0/xuxkRoles", produces = MediaType.APPLICATION_JSON_VALUE)
    @OauthLog(eventName = "新增角色信息")
    public Integer saveXuxkRole(@RequestBody XuxkRole xuxkRole) {

        return  xuxkRoleService.insertXuxkRole(xuxkRole);

    }

    /**
     * 部分更新
     * @param xuxkRole
     * @return
     */
    @PatchMapping(value="/v1.0/xuxkRoles/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @OauthLog(eventName = "部分更新角色信息")
    public Integer patchUpdateXuxkRole(@PathVariable Integer id,@RequestBody XuxkRole xuxkRole) {
        xuxkRole.setId(id);

        return   xuxkRoleService.patchUpdateXuxkRole(xuxkRole);


    }
    /**
     * 整体更新
     * @param xuxkRole
     * @return
     */
    @PutMapping(value="/v1.0/xuxkRoles/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public Integer updateXuxkRole(@PathVariable Integer id,@RequestBody XuxkRole xuxkRole) {

        xuxkRole.setId(id);

        return  xuxkRoleService.updateXuxkRole(xuxkRole);
    }


    @DeleteMapping(value="/v1.0/xuxkRoles/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @OauthLog(eventName = "删除角色信息")
    public Integer deleteXuxkRole(@PathVariable Integer id) {

        xuxkRoleService.deleteXuxkRole(id);

        return 1 ;

    }

}
